
//
//  StoreEntranceViewController.m
//  NordsonTesco
//
//  Created by CccDaxIN on 16/7/4.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "StoreEntranceViewController.h"
#import "StoreEntranceTableViewCell.h"

@interface StoreEntranceViewController ()<UITextFieldDelegate>
{
    UITableView *storeEntranceTableView;
    UISegmentedControl *segmentControl;
}
@end

@implementation StoreEntranceViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"店铺名称";
    self.view.backgroundColor = [UIColor whiteColor];
    [self orderInquirySwitch];
    [self createStoreEntranceTableView];
    
    UIButton *storeEntranceBackButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [storeEntranceBackButton addTarget:self action:@selector(storeEntranceBackButtonAction) forControlEvents:UIControlEventTouchUpInside];
    CGSize storeEntranceBackButtonSize = CGSizeMake(15, 30);
    storeEntranceBackButton.frame = CGRectMake(storeEntranceBackButton.frame.origin.x, storeEntranceBackButton.frame.origin.y, storeEntranceBackButtonSize.width, storeEntranceBackButtonSize.height);
    storeEntranceBackButton.titleLabel.font = [UIFont boldSystemFontOfSize:12];
    [storeEntranceBackButton setImage:[UIImage imageNamed:@"arrow---left"] forState:UIControlStateNormal];
    UIBarButtonItem *leftButtonItem = [[UIBarButtonItem alloc] initWithCustomView:storeEntranceBackButton];
    self.navigationItem.leftBarButtonItem = leftButtonItem;
    // Do any additional setup after loading the view.
}
- (void)storeEntranceBackButtonAction{
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
}
#pragma mark -- 订单查询切换
- (void)orderInquirySwitch{
    NSArray *array=@[@"添加线下订单",@"查询"];
    segmentControl=[[UISegmentedControl alloc]initWithItems:array];
    segmentControl.frame=CGRectMake(20,80,kScrernWidth-40, 35);
    segmentControl.selectedSegmentIndex = 0;
    segmentControl.tintColor=[UIColor colorWithRed:0.97 green:0.54 blue:0.36 alpha:1.00];
    [segmentControl addTarget:self action:@selector(changeSegment:) forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:segmentControl];
    
}
- (void)changeSegment:(UISegmentedControl *)segment{
    NSLog(@"segmentControl %ld",(long)segmentControl.selectedSegmentIndex);
    if (segmentControl.selectedSegmentIndex == 0) {
        NSLog(@"添加线下订单");
        [storeEntranceTableView reloadData];
        
    }else if (segmentControl.selectedSegmentIndex == 1){
        NSLog(@"查询");
        [storeEntranceTableView reloadData];
    }
}

-(BOOL)textFieldShouldReturn:(UITextField *)textField {
    [textField resignFirstResponder];
    return YES;
}
#pragma mark --  创建tableview
- (void)createStoreEntranceTableView{
    storeEntranceTableView =[[UITableView alloc]initWithFrame:CGRectMake(0,115, kScrernWidth,kScrernHeight-115) style:UITableViewStylePlain];
    storeEntranceTableView.delegate=self;
    storeEntranceTableView.dataSource=self;
    storeEntranceTableView.tableFooterView = [[UIView alloc] init];
    [storeEntranceTableView setSeparatorColor:[UIColor whiteColor ]];
    //    storeEntranceTableView.separatorStyle=UITableViewCellSeparatorStyleSingleLine;
    [self.view addSubview:storeEntranceTableView];
    
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    NSInteger number;
    if (segmentControl.selectedSegmentIndex == 0) {
        number = 5;
    }else if (segmentControl.selectedSegmentIndex == 1){
        number = 10;
    }
    return number;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (segmentControl.selectedSegmentIndex == 0 ) {
        if (indexPath.section == 0 && indexPath.row == 2) {
            return 100;
        }
        return  80;
    }else if (segmentControl.selectedSegmentIndex == 1){
        return  185;
    }
    return 80;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    StoreEntranceTableViewCell *cell;
    if (segmentControl.selectedSegmentIndex == 0) {
        static NSString *identifer=@"Mycell";
        UITableViewCell *MyCell=[tableView cellForRowAtIndexPath:indexPath];
        if (MyCell==nil) {
            MyCell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifer];
        }
        MyCell.selectionStyle = UITableViewCellSelectionStyleNone;
//                [storeEntranceTableView setSeparatorColor:[UIColor colorWithRed:0.82 green:0.83 blue:0.83 alpha:1.00]];
        [storeEntranceTableView setSeparatorColor:[UIColor whiteColor]];
        
        NSArray *arrayOne = @[@"消费者手机号:",@"姓名:"];
        NSArray *arrayTwo = @[@"订单内容:",@"用户名:"];
        NSArray *arrayThree = @[@"支付金额:",@"消费者订单"];
        NSArray *arrayFour = @[@"服务费:",@"剩余益购币:"];
        if (indexPath.section ==0 && indexPath.row == 0) {
            
            for (int i = 0; i < 2; i++) {
                UILabel *label_Phone = [[UILabel alloc]init];
                label_Phone.frame = CGRectMake(20,13+30*i,110, 25);
                label_Phone.textAlignment = NSTextAlignmentRight;
                label_Phone.font = [UIFont systemFontOfSize:15];
                label_Phone.text = [arrayOne objectAtIndex:i];
                [MyCell addSubview:label_Phone];
            }
            UITextField *field_phone = [[UITextField alloc]initWithFrame:CGRectMake(140, 13, kScrernWidth-180, 25)];
            field_phone.delegate = self;
            field_phone.borderStyle = UITextBorderStyleRoundedRect;
            [MyCell addSubview:field_phone];
            
            UILabel *label_name = [[UILabel alloc]init];
            label_name.frame = CGRectMake(140,40,kScrernWidth-170, 25);
            label_name.textAlignment = NSTextAlignmentLeft;
            label_name.font = [UIFont systemFontOfSize:15];
            label_name.text = @"";
            [MyCell addSubview:label_name];
            
            UIView *oneView = [[UIView alloc]initWithFrame:CGRectMake(20, 79, kScrernWidth-20, 1)];
            oneView.backgroundColor = [UIColor colorWithRed:0.89 green:0.89 blue:0.89 alpha:1.00];
            [MyCell addSubview:oneView];
            
        }else if (indexPath.section ==0 && indexPath.row == 1){
            for (int i = 0; i < 2; i++) {
                UILabel *label_content = [[UILabel alloc]init];
                label_content.frame = CGRectMake(20,10+30*i,110, 25);
                label_content.textAlignment = NSTextAlignmentRight;
                label_content.font = [UIFont systemFontOfSize:15];
                label_content.text = [arrayTwo objectAtIndex:i];
                [MyCell addSubview:label_content];
            }
            //订单内容
            UITextField *field_content = [[UITextField alloc]initWithFrame:CGRectMake(140, 13, kScrernWidth-180, 25)];
            field_content.delegate = self;
            field_content.borderStyle = UITextBorderStyleRoundedRect;
            [MyCell addSubview:field_content];
            //用户名
            UILabel *label_userName = [[UILabel alloc]init];
            label_userName.frame = CGRectMake(140,40,kScrernWidth-170, 25);
            label_userName.textAlignment = NSTextAlignmentLeft;
            label_userName.font = [UIFont systemFontOfSize:15];
            label_userName.text = @"";
            [MyCell addSubview:label_userName];
            
            UIView *twoView = [[UIView alloc]initWithFrame:CGRectMake(20, 79, kScrernWidth-20, 1)];
            twoView.backgroundColor = [UIColor colorWithRed:0.89 green:0.89 blue:0.89 alpha:1.00];
            [MyCell addSubview:twoView];
            
        }else if (indexPath.section == 0 && indexPath.row == 2){
            for (int i = 0; i < 2; i++) {
                UILabel *label_paymentAmount = [[UILabel alloc]init];
                label_paymentAmount.frame = CGRectMake(20,12+30*i,110, 25);
                label_paymentAmount.textAlignment = NSTextAlignmentRight;
                label_paymentAmount.font = [UIFont systemFontOfSize:15];
                label_paymentAmount.text = [arrayThree objectAtIndex:i];
                [MyCell addSubview:label_paymentAmount];
            }
            UILabel *label_paymentAmount = [[UILabel alloc]init];
            label_paymentAmount.frame = CGRectMake(20,65,110, 20);
            label_paymentAmount.textAlignment = NSTextAlignmentRight;
            label_paymentAmount.font = [UIFont systemFontOfSize:15];
            label_paymentAmount.text = @"支付方式:";
            [MyCell addSubview:label_paymentAmount];
            
            //支付金额
            UITextField *field_paymentAmount = [[UITextField alloc]initWithFrame:CGRectMake(140, 12, kScrernWidth-180, 25)];
            field_paymentAmount.delegate = self;
            field_paymentAmount.borderStyle = UITextBorderStyleRoundedRect;
            [MyCell addSubview:field_paymentAmount];
            //元
            UILabel *label_yuan = [[UILabel alloc]init];
            label_yuan.frame = CGRectMake(kScrernWidth-35,12,15, 25);
            label_yuan.textAlignment = NSTextAlignmentLeft;
            label_yuan.textColor = [UIColor grayColor];
            label_yuan.font = [UIFont systemFontOfSize:13];
            label_yuan.text = @"元";
            [MyCell addSubview:label_yuan];
            
            UILabel *label_biaoji = [[UILabel alloc]init];
            label_biaoji.frame = CGRectMake(kScrernWidth-20,12,7, 25);
            label_biaoji.textAlignment = NSTextAlignmentLeft;
            label_biaoji.textColor = [UIColor grayColor];
            label_biaoji.font = [UIFont systemFontOfSize:13];
            label_biaoji.textColor = [UIColor redColor];
            label_biaoji.text = @"*";
            [MyCell addSubview:label_biaoji];
            
            //线下支付
            UIImageView *xianxiaPay = [[UIImageView alloc]initWithFrame:CGRectMake(140, 60, 10, 10)];
            xianxiaPay.image = [UIImage imageNamed:@"1"];
            //            xianxiaPay.backgroundColor = [UIColor greenColor];
            [MyCell addSubview:xianxiaPay];
            
            UILabel *label_xianxiaPay = [[UILabel alloc]initWithFrame:CGRectMake(155, 55, 60, 20)];
            label_xianxiaPay.textAlignment = NSTextAlignmentLeft;
            //            label_xianxiaPay.backgroundColor = [UIColor grayColor];
            label_xianxiaPay.font = [UIFont systemFontOfSize:13];
            label_xianxiaPay.textColor = [UIColor colorWithRed:0.71 green:0.72 blue:0.72 alpha:1.00];
            label_xianxiaPay.text = @"线下支付";
            [MyCell addSubview:label_xianxiaPay];
            
            UIButton *xianxiaPay_button = [UIButton buttonWithType:UIButtonTypeCustom];
            [xianxiaPay_button addTarget:self action:@selector(xianxiaPayAndYigoubiButtonkAction:) forControlEvents:UIControlEventTouchUpInside];
            xianxiaPay_button.tag = 500;
            xianxiaPay_button.frame = CGRectMake(140,55,70,20);
            //            xianxiaPay_button.backgroundColor = [UIColor redColor];
            [MyCell addSubview:xianxiaPay_button];
            
            /****   ****/
            
            //益购币支付
            UIImageView *yigoubiPay = [[UIImageView alloc]initWithFrame:CGRectMake(230, 60, 10, 10)];
            yigoubiPay.image = [UIImage imageNamed:@"1"];
            //            yigoubiPay.backgroundColor = [UIColor greenColor];
            [MyCell addSubview:yigoubiPay];
            
            UILabel *label_yigoubiPay = [[UILabel alloc]initWithFrame:CGRectMake(245, 55, 60, 20)];
            label_yigoubiPay.textAlignment = NSTextAlignmentLeft;
            //            label_yigoubiPay.backgroundColor = [UIColor grayColor];
            label_yigoubiPay.font = [UIFont systemFontOfSize:13];
            label_yigoubiPay.textColor = [UIColor colorWithRed:0.71 green:0.72 blue:0.72 alpha:1.00];
            label_yigoubiPay.text = @"益购币";
            [MyCell addSubview:label_yigoubiPay];
            
            UIButton *yigoubiPay_button = [UIButton buttonWithType:UIButtonTypeCustom];
            [yigoubiPay_button addTarget:self action:@selector(xianxiaPayAndYigoubiButtonkAction:) forControlEvents:UIControlEventTouchUpInside];
            yigoubiPay_button.tag = 501;
            yigoubiPay_button.frame = CGRectMake(230,55,70,20);
            //            yigoubiPay_button.backgroundColor = [UIColor redColor];
            [MyCell addSubview:yigoubiPay_button];
            
            UIView *threeView = [[UIView alloc]initWithFrame:CGRectMake(20, 99, kScrernWidth-20, 1)];
            threeView.backgroundColor = [UIColor colorWithRed:0.89 green:0.89 blue:0.89 alpha:1.00];
            [MyCell addSubview:threeView];
            
        }else if (indexPath.section == 0 && indexPath.row == 3){
            for (int i = 0; i < 2; i++) {
                UILabel *label_serviceCharges = [[UILabel alloc]init];
                label_serviceCharges.frame = CGRectMake(20,13+30*i,110, 25);
                label_serviceCharges.textAlignment = NSTextAlignmentRight;
                label_serviceCharges.font = [UIFont systemFontOfSize:15];
                label_serviceCharges.text = [arrayFour objectAtIndex:i];
                [MyCell addSubview:label_serviceCharges];
            }
            //服务费
            UILabel *label_fuwufei = [[UILabel alloc]init];
            label_fuwufei.frame = CGRectMake(140,13,100, 25);
            label_fuwufei.textAlignment = NSTextAlignmentLeft;
            label_fuwufei.font = [UIFont systemFontOfSize:13];
            label_fuwufei.text = @"";
            [MyCell addSubview:label_fuwufei];
            
            //益购币
            UILabel *label_yigoubi = [[UILabel alloc]init];
            label_yigoubi.frame = CGRectMake(140,43,50, 25);
            label_yigoubi.textAlignment = NSTextAlignmentLeft;
            label_yigoubi.font = [UIFont systemFontOfSize:13];
            label_yigoubi.textColor = [UIColor colorWithRed:0.71 green:0.72 blue:0.72 alpha:1.00];
            label_yigoubi.text = @"0.00个";
            [MyCell addSubview:label_yigoubi];
            
            UIView *fourView = [[UIView alloc]initWithFrame:CGRectMake(20, 79, kScrernWidth-20, 1)];
            fourView.backgroundColor = [UIColor colorWithRed:0.89 green:0.89 blue:0.89 alpha:1.00];
            [MyCell addSubview:fourView];
            
        }
        else if (indexPath.section == 0 &&indexPath.row == 4){
            
            UIButton *sure_button = [UIButton buttonWithType:UIButtonTypeCustom];
            [sure_button addTarget:self action:@selector(sureButtonkAction) forControlEvents:UIControlEventTouchUpInside];
            [sure_button setTitle:@"确定" forState:UIControlStateNormal];
            sure_button.layer.masksToBounds = YES;
            sure_button.layer.cornerRadius = 5;
            sure_button.frame = CGRectMake(storeEntranceTableView.center.x-75,23,150,35);
            sure_button.backgroundColor = [UIColor colorWithRed:0.98 green:0.32 blue:0.12 alpha:1.00];
            [MyCell addSubview:sure_button];
            
        }
        return MyCell;
    }else if (segmentControl.selectedSegmentIndex == 1){
        cell = [tableView dequeueReusableCellWithIdentifier:@"storeCell"];
        if (cell == nil) {
            cell = [[[NSBundle mainBundle] loadNibNamed:@"StoreEntranceTableViewCell" owner:nil options:nil] firstObject];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        [storeEntranceTableView setSeparatorColor:[UIColor whiteColor]];
        return cell;
    }
    return nil;
}

#pragma mark --  支付
- (void)xianxiaPayAndYigoubiButtonkAction:(UIButton *)sender{
    switch (sender.tag) {
        case 500:{
            NSLog(@"线下");
        }
            break;
        case 501:{
            NSLog(@"益购币");
        }
            break;
        default:
            break;
    }
    
}
//确定
- (void)sureButtonkAction{
    NSLog(@"确定");
    
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
   
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
